package com.lw;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;

/**
 * @author LW
 * @2020/8/31 11:46
 */
public class TestSW {

    public static void main(String[] args) {
        Jedis jedis = new Jedis("localhost",6379);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("hello","world");
        jsonObject.put("a","1");
        //开启事务
        Transaction multi = jedis.multi();
        String s = jsonObject.toJSONString();

        try {
            multi.set("uu",s);
            //事务的执行
            multi.exec();
        } catch (Exception e) {
            e.printStackTrace();
            //事务的放弃
            multi.discard();
        } finally {
            System.out.println(jedis.get("uu"));
            jedis.close();
        }
    }
}
